﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using QXGameEngine.Logic;

namespace QXGameEngine.Control {

    public partial class QXFacePlate : UserControl {

        /// <summary>
        /// 头像面板控件
        /// </summary>
        /// <param name="type">面板类型</param>
        public QXFacePlate(RoleFaceTypes type) {
            InitializeComponent();
            InitializeRainbowBrush();
            switch (type) {
                case RoleFaceTypes.Leader:
                    //面板背景
                    Container.Width = 474; Container.Height = 66;
                    Container.Background = new ImageBrush() { ImageSource = Super.GetImage("/Image/Interface/Plate/LeaderFacePlate.png") };
                    //头像设置
                    Face.Width = 30; 
                    Face.Height = 30;
                    Canvas.SetLeft(Face, 52); Canvas.SetTop(Face, 12);
                    //等级位置
                    LevelGrid.Width = 30; LevelGrid.Height = 13;
                    Canvas.SetLeft(LevelGrid, 53); Canvas.SetTop(LevelGrid, 47);
                    //经验值位置
                    ExperiencePanel.Width = 277;
                    Canvas.SetLeft(ExperiencePanel, 111); Canvas.SetTop(ExperiencePanel, 6);
                    Experience.RadiusX = 4; Experience.RadiusY = 4;
                    Experience.Height = 9;
                    Experience.Fill = rainbowBrush[3];
                    Experience.HorizontalAlignment = HorizontalAlignment.Left;
                    Canvas.SetLeft(ExperienceValueGrid, 111); Canvas.SetTop(ExperienceValueGrid, 4);
                    ExperienceValueGrid.Width = 277; ExperienceValueGrid.Height = 12;
                    //经验值遮挡物
                    ExperienceMask.Width = 278; ExperienceMask.Height = 9;
                    ExperienceMask.Fill = new ImageBrush() { ImageSource = Super.GetImage("/Image/Interface/Plate/ExperienceMask.png") };
                    Canvas.SetLeft(ExperienceMask, 110); Canvas.SetTop(ExperienceMask, 6);
                    //生命条设置
                    LifePanel.Width = 108; 
                    Canvas.SetLeft(LifePanel, 198); Canvas.SetTop(LifePanel, 19);
                    Life.RadiusX = 4; Life.RadiusY = 4;
                    Life.Height = 14;
                    Life.Fill = rainbowBrush[0];
                    Life.HorizontalAlignment = HorizontalAlignment.Left;
                    LifeValue.Margin = new Thickness(0, -15, 0, 0);
                    //魔法条设置
                    MagicPanel.Width = 84;
                    Canvas.SetLeft(MagicPanel, 98); Canvas.SetTop(MagicPanel, 19);
                    Magic.RadiusX = 4; Magic.RadiusY = 4;
                    Magic.Height = 10;
                    Magic.Fill = rainbowBrush[1];
                    Magic.HorizontalAlignment = HorizontalAlignment.Left;
                    MagicValue.Margin = new Thickness(0, -12, 0, 0);
                    //活力条设置
                    EnergyPanel.Width = 84; 
                    Canvas.SetLeft(EnergyPanel, 322); Canvas.SetTop(EnergyPanel, 19);
                    Energy.RadiusX = 4; Energy.RadiusY = 4;
                    Energy.Height = 10;
                    Energy.Fill = rainbowBrush[2];
                    Energy.HorizontalAlignment = HorizontalAlignment.Left;
                    EnergyValue.Margin = new Thickness(0, -12, 0, 0);
                    //额外属性描述图标容器
                    Canvas.SetLeft(AdditionalEffectPanel, 195); Canvas.SetTop(AdditionalEffectPanel, 39);
                    //其他均不需要
                    SName.Visibility = Visibility.Collapsed;
                    break;
                case RoleFaceTypes.Object:
                    //面板背景
                    Container.Width = 162; Container.Height = 63;
                    Container.Background = new ImageBrush() { ImageSource = Super.GetImage("/Image/Interface/Plate/ObjectFacePlate.png") };
                    ////头像设置(对头像进行水平翻转)
                    //Face.RenderTransform = new TransformGroup() {
                    //    Children = new TransformCollection() {
                    //        new RotateTransform(){ CenterX = 26, Angle = 180 },
                    //        new ScaleTransform(){ ScaleY = -1 }
                    //    }
                    //};
                    Face.Width = 30; Face.Height = 30;
                    Canvas.SetLeft(Face, 11); Canvas.SetTop(Face, 11);
                    //等级位置
                    LevelGrid.Width = 30; LevelGrid.Height = 13;
                    Canvas.SetLeft(LevelGrid, 10); Canvas.SetTop(LevelGrid, 44);
                    //生命条设置
                    LifePanel.Width = 104;
                    Canvas.SetLeft(LifePanel, 48); Canvas.SetTop(LifePanel, 8);
                    Life.Height = 14;
                    Life.Fill = rainbowBrush[0];
                    Life.HorizontalAlignment = HorizontalAlignment.Left;
                    Life.Margin = new Thickness(0, 2, 0, 0);
                    LifeValue.Margin = new Thickness(0, -15, 0, 0);
                    //额外属性描述图标容器
                    Canvas.SetLeft(AdditionalEffectPanel, 50); Canvas.SetTop(AdditionalEffectPanel, 48);
                    //其他均不需要
                    ExperienceValueGrid.Visibility = Visibility.Collapsed;
                    Experience.Visibility = Visibility.Collapsed;
                    ExperiencePanel.Visibility = Visibility.Collapsed;
                    MagicPanel.Visibility = Visibility.Collapsed;
                    EnergyPanel.Visibility = Visibility.Collapsed;
                    break;
                case RoleFaceTypes.Team:

                    break;
            }
        }

        /// <summary>
        /// 获取或设置处于屏幕中的X位置
        /// </summary>
        public double Left {
            get { return (double)this.GetValue(Canvas.LeftProperty); }
            set { this.SetValue(Canvas.LeftProperty, value); }
        }

        /// <summary>
        /// 获取或设置处于屏幕中的Y位置
        /// </summary>
        public double Top {
            get { return (double)this.GetValue(Canvas.TopProperty); }
            set { this.SetValue(Canvas.TopProperty, value); }
        }

        /// <summary>
        /// 获取或设置层次深度
        /// </summary>
        public int ZIndex {
            get { return (int)this.GetValue(Canvas.ZIndexProperty); }
            set { this.SetValue(Canvas.ZIndexProperty, value); }
        }

        /// <summary>
        /// 设置显示的名字
        /// </summary>
        public string VSName {
            set { SName.Text = value; }
        }

        /// <summary>
        /// 设置显示的等级
        /// </summary>
        public string VLevel {
            set { Level.Text = value; }
        }

        /// <summary>
        /// 设置显示的头像图片代号
        /// </summary>
        public int FaceSign {
            set {
                Face.Fill = new ImageBrush() {
                    ImageSource = Super.GetImage(string.Format("/Image/Face/{0}.jpg", value))
                };
            }
        }

        /// <summary>
        /// 获取生命值矩形条容器宽度
        /// </summary>
        public double LifeTotalWidth {
            get { return LifePanel.Width; }
        }

        /// <summary>
        /// 设置显示的生命值矩形条当前宽度
        /// </summary>
        public double LifeWidth {
            set { Life.Width = value; }
        }

        /// <summary>
        /// 设置显示的生命数值
        /// </summary>
        public string LifeText {
            set { LifeValue.Text = value; }
        }

        /// <summary>
        /// 获取魔法值矩形条容器宽度
        /// </summary>
        public double MagicTotalWidth {
            get { return MagicPanel.Width; }
        }

        /// <summary>
        /// 设置显示的魔法值矩形条当前宽度
        /// </summary>
        public double MagicWidth {
            set { Magic.Width = value; }
        }

        /// <summary>
        /// 设置显示的魔法数值
        /// </summary>
        public string MagicText {
            set { MagicValue.Text = value; }
        }

        /// <summary>
        /// 获取活力值矩形条容器宽度
        /// </summary>
        public double EnergyTotalWidth {
            get { return EnergyPanel.Width; }
        }

        /// <summary>
        /// 设置显示的活力值矩形条当前宽度
        /// </summary>
        public double EnergyWidth {
            set { Energy.Width = value; }
        }

        /// <summary>
        /// 设置显示的活力数值
        /// </summary>
        public string EnergyText {
            set { EnergyValue.Text = value; }
        }

        /// <summary>
        /// 获取控件宽度
        /// </summary>
        public double BackWidth {
            get { return Container.Width; }
        }

        /// <summary>
        /// 获取经验值矩形条容器宽度
        /// </summary>
        public double ExperienceTotalWidth {
            get { return ExperiencePanel.Width; }
        }

        /// <summary>
        /// 设置显示的经验值矩形条当前宽度
        /// </summary>
        public double ExperienceWidth {
            set { Experience.Width = value; }
        }

        /// <summary>
        /// 获取或设置经验值显示
        /// </summary>
        public string ExperienceText {
            get { return ExperienceValue.Text; }
            set { ExperienceValue.Text = value; }
        }

        /// 血、魔、活、经4值彩虹笔刷
        LinearGradientBrush[] rainbowBrush = new LinearGradientBrush[4];
        /// <summary>
        /// 初始化彩虹笔刷
        /// </summary>
        private void InitializeRainbowBrush() {
            //生命值笔刷
            rainbowBrush[0] = Super.CreateRainbowBrush(81, 9, 10, 228, 6, 17);
            //魔法值笔刷
            rainbowBrush[1] = Super.CreateRainbowBrush(3, 36, 89, 35, 73, 182);
            //活力值笔刷
            rainbowBrush[2] = Super.CreateRainbowBrush(14, 77, 20, 26, 181, 51);
            //经验值笔刷
            rainbowBrush[3] = Super.CreateRainbowBrush(202, 95, 235, 77, 40, 92);
        }
    }
}
